package com.yuanfeng.payment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.util.querypage.PageUtils;
import com.yuanfeng.commoms.util.querypage.Query;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import com.yuanfeng.payment.entity.PayFxRecordEntity;
import com.yuanfeng.payment.mapper.PayFxRecordMapper;
import com.yuanfeng.payment.service.PayFxRecordService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 *
 */
@Service
public class PayFxRecordServiceImpl extends ServiceImpl<PayFxRecordMapper, PayFxRecordEntity>
    implements PayFxRecordService{

    @Override
    public ResponseResult query(Map<String, Object> param) {
        UserInfoVO ui = ParseTokenUtils.getUserInfoByToken(param.get("token").toString());
        if (ui == null) {
            return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
        }
        param.put("userId",ui.getUserId());
        IPage<PayFxRecordEntity> payFxRecordList = this.page(new Query<PayFxRecordEntity>().getPage(param),
                new LambdaQueryWrapper<PayFxRecordEntity>()
                        .eq(PayFxRecordEntity::getUserId, ui.getUserId())
                        .eq(PayFxRecordEntity::getRecordStatus,2)
                        .orderByDesc(PayFxRecordEntity::getCreateTime));
        return ResponseResult.success(PageUtils.getPage(payFxRecordList));
    }
}




